const errorStr = '不得为空'
const sortReg = /^([1-9]\d*|[0]{1,1})$/ // 含零的正整数正则
const priceReg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/ // 含零的正整数正则 小数两位
const phoneReg = /^1[3|4|5|7|8][0-9]{9}$/ // 手机号正则
const hrefStrRegex = '^((https|http|ftp)://)?' + '(([\\w_!~*\'()\\.&=+$%-]+: )?[\\w_!~*\'()\\.&=+$%-]+@)?' + '(([0-9]{1,3}\\.){3}[0-9]{1,3}' + '|' + '(localhost)|' + '([\\w_!~*\'()-]+\\.)*' + '\\w+\\.' + '[a-zA-Z]{1,6})' + '(:[0-9]{1,5})?' + '((/?)|' + '(/[\\w_!~*\'()\\.;?:@&=+$,%#-]+)+/?)$'
const hrefReg = new RegExp(hrefStrRegex)

const ComRules = {
  mobile: [{
    required: true,
    message: '手机号' + errorStr,
    trigger: 'blur'
  },
  {
    pattern: phoneReg,
    message: '手机号格式有误!',
    trigger: 'blur'
  }
  ],
  password: [{
    required: true,
    message: '密码' + errorStr,
    trigger: 'blur'
  }, {
    // pattern: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,30}$/,
    message: '密码不少于8位，至少包含一个字母和一个数字',
    trigger: 'blur'
  }],
  price: [{
    required: true,
    message: '金额' + errorStr,
    trigger: 'blur,change'
  }, {
    pattern: priceReg,
    message: '金额格式错误!(整数或者两位小数)',
    trigger: 'blur,change'
  }],
  smsCode: [{
    required: true,
    message: '验证码' + errorStr,
    trigger: 'blur'
  }, {
    pattern: /^\d{6}$/,
    message: '验证码格式错误',
    trigger: 'blur'
  }]
}

// 登录 form 校验
export const LoginRules = {
  account: [{
    required: true,
    message: '账号' + errorStr,
    trigger: 'blur'
  }],
  password: [{
    required: true,
    message: '密码' + errorStr,
    trigger: 'blur'
  }, {
    pattern: /^.{6,}$/,
    message: '密码不得少于6位',
    trigger: 'blur'
  }],
  personMobile: ComRules.mobile,
  smsCode: ComRules.smsCode

}

// 修改密码 form 校验
export const EditPwdRules = {
  oldPassword: [{
    required: true,
    message: '旧密码' + errorStr,
    trigger: 'blur'
  }],
  password: [{
    required: true,
    message: '新密码' + errorStr,
    trigger: 'blur'
  }, {
    // pattern: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/,
    pattern: /^.{6,}$/,
    message: '密码不得少于6位',
    trigger: 'blur'
  }]
}

// 用户信息 form 校验
export const UserInfoRules = {
  personName: [{
    required: true,
    message: '用户名' + errorStr,
    trigger: 'blur'
  }],
  personMobile: ComRules.mobile,
  roleId: [{
    required: true,
    message: '角色' + errorStr,
    trigger: 'change'
  }]
}

// 角色 form 校验
export const RoleInfoRules = {
  name: [{
    required: true,
    message: '角色名称' + errorStr,
    trigger: 'blur'
  }],
  remark: [{
    required: true,
    message: '角色概述' + errorStr,
    trigger: 'blur'
  }]
}

export const addProductFormRulse = {
  name: [{
    required: true,
    message: '商品名称' + errorStr,
    trigger: 'blur'
  }],
  productCategoryIds: [{
    required: true,
    message: '商品分类' + errorStr,
    trigger: 'change'
  }],
  groupIds: [{
    required: true,
    message: '商品分组' + errorStr,
    trigger: 'change'
  }],
  pic: [{
    required: true,
    message: '商品封面图' + errorStr,
    trigger: 'change'
  }],
  albumPics: [{
    required: true,
    message: '商品轮播图' + errorStr,
    trigger: 'change'
  }],
  detailDesc: [{
    required: true,
    message: '商品详情图' + errorStr,
    trigger: 'change'
  }],
  price: [{
    required: true,
    message: '商品价格' + errorStr,
    trigger: 'blur'
  }, {
    pattern: priceReg,
    message: '商品价格格式有误! (两位小数或者整数)',
    trigger: 'blur'
  }],
  productSn: [{
    required: true,
    message: '商品编码' + errorStr,
    trigger: 'blur'
  }],
  stock: [{
    required: true,
    message: '商品库存' + errorStr,
    trigger: 'blur'
  }],  
  costPrice: [{
    required: true,
    message: '成本价' + errorStr,
    trigger: 'blur'
  }],
  linePrice: [{
    required: true,
    message: '划线价' + errorStr,
    trigger: 'blur'
  }, {
    pattern: priceReg,
    message: '划线价格格式有误! (两位小数或者整数)',
    trigger: 'blur'
  }],
  usePointLimit: [{
    pattern: sortReg,
    message: '积分价格格式错误(正整数)',
    trigger: 'blur'
  }],
  buyerLimit: [{
    pattern: sortReg,
    message: '限购次数格式错误',
    trigger: 'blur'
  }],
  serviceIdList: [{
    required: true,
    message: '服务承诺' + errorStr,
    trigger: 'blur'
  }]
}

export const orderSendFormRules = {
  deliveryCompany: [{
    required: true,
    message: '快递公司' + errorStr,
    trigger: 'change'
  }],
  deliverySn: [{
    required: true,
    message: '快递单号' + errorStr,
    trigger: 'blur'
  }]
}

/* 商品分类 */
export const productClassRules = {
  name: [{
    required: true,
    message: '分类名称' + errorStr,
    trigger: 'blur'
  }],
  sort: [{
    required: true,
    message: '分类排序' + errorStr,
    trigger: 'blur'
  }, {
    pattern: sortReg,
    message: '排序格式有误!',
    trigger: 'blur'
  }]
}

/* 商品分组 */
export const productGroupRules = {
  groupName: [{
    required: true,
    message: '分组名称' + errorStr,
    trigger: 'blur'
  }],
  groupSort: [{
    required: true,
    message: '分组排序' + errorStr,
    trigger: 'blur'
  }, {
    pattern: sortReg,
    message: '排序格式有误!',
    trigger: 'blur'
  }]
}

// 服务承诺 form 校验
export const servicePromiseRules = {
  name: [{
    required: true,
    message: '服务承诺名称' + errorStr,
    trigger: 'blur'
  }],
  descrition: [{
    required: true,
    message: '承诺内容' + errorStr,
    trigger: 'blur'
  }]
}

// 退货地址 form 校验
export const returnAddressRules = {
  name: [{
    required: true,
    message: '退货地址收货人' + errorStr,
    trigger: 'blur'
  }],
  phone: [{
    required: true,
    message: '联系电话' + errorStr,
    trigger: 'blur'
  }, {
    pattern: phoneReg,
    message: '手机号格式有误!',
    trigger: 'blur'
  }],
  area: [{
    required: true,
    message: '省市区' + errorStr,
    trigger: 'blur'
  }]
}

/* 品牌列表 */
export const brandFormRules = {
  name: [{
    required: true,
    message: '品牌名称' + errorStr,
    trigger: 'blur'
  }],
  sort: [{
    pattern: sortReg,
    message: '排序格式有误!',
    trigger: 'blur'
  }],
  logo: [{
    required: true,
    message: '品牌Logo' + errorStr,
    trigger: 'change'
  }]
}

/* 轮播图 */
export const bannerFormRules = {
  title: [{
    required: true,
    message: '轮播图标题' + errorStr,
    trigger: 'blur'
  }],
  href: [{
    pattern: hrefReg,
    message: '跳转链接格式有误!',
    trigger: 'blur'
  }],
  imgUrl: [{
    required: true,
    message: '轮播图图片' + errorStr,
    trigger: 'change'
  }]
}

/* 店铺 */
export const StoreInfoRules = {
  name: [{
    required: true,
    message: '店铺名称' + errorStr,
    trigger: 'blur'
  }],
  scope: [{
    required: true,
    message: '店铺经营范围' + errorStr,
    trigger: 'blur'
  }],
  contactPerson: [{
    required: true,
    message: '店铺联系人' + errorStr,
    trigger: 'blur'
  }],
  contactNumber: [{
    required: true,
    message: '店铺联系人电话' + errorStr,
    trigger: 'blur'
  }, {
    pattern: phoneReg,
    message: '手机号格式有误!',
    trigger: 'blur'
  }]
}

/* 课程 */
export const CourseFormRules = {
  title: [{
    required: true,
    message: '课程名称' + errorStr,
    trigger: 'blur'
  }],
  bSort: [{
    pattern: sortReg,
    message: '排序格式有误!',
    trigger: 'blur'
  }],
  pic: [{
    required: true,
    message: '课程封面图片' + errorStr,
    trigger: 'change'
  }],
  vidioUrl: [{
    required: true,
    message: '课程视频' + errorStr,
    trigger: 'change'
  }],
  vidioTime: [{
    required: true,
    message: '视频时间' + errorStr,
    trigger: 'change'
  }, {
    pattern: sortReg,
    message: '视频时间格式有误!',
    trigger: 'change'
  }],
  useTime: [{
    required: true,
    message: '学习时间' + errorStr,
    trigger: 'change'
  }, {
    pattern: sortReg,
    message: '学习时间格式有误!',
    trigger: 'change'
  }]
}

/* 试题 */
export const QuestionsFormRules = {
  title: [{
    required: true,
    message: '题目' + errorStr,
    trigger: 'blur'
  }],
  maxScore: [{
    required: true,
    message: '分值' + errorStr,
    trigger: 'blur'
  }, {
    pattern: sortReg,
    message: '分值格式有误!',
    trigger: 'blur'
  }],
  type: [{
    required: true,
    message: '题目类型' + errorStr,
    trigger: 'change'
  }],
  difficult: [{
    required: true,
    message: '题目难度' + errorStr,
    trigger: 'change'
  }],
  courseId: [{
    required: true,
    message: '所属课程' + errorStr,
    trigger: 'change'
  }],
  rightAnswer: [{
    required: true,
    message: '正确答案' + errorStr,
    trigger: 'blur,change'
  }],
  answerOptions: [{
    required: true,
    message: '选项' + errorStr,
    trigger: 'blur,change'
  }]
}

/* 试卷 */
export const PaperFormRules = {
  title: [{
    required: true,
    message: '试卷标题' + errorStr,
    trigger: 'blur'
  }],
  maxScore: [{
    required: true,
    message: '试卷分值' + errorStr,
    trigger: 'blur'
  }],
  topicCount: [{
    required: true,
    message: '试卷题目数' + errorStr,
    trigger: 'blur'
  }],
  topicIds: [{
    required: true,
    message: '试卷题目' + errorStr,
    trigger: 'blur,change'
  }]
}

/* 试题规则 */
export const PaperRuleRules = {
  type: [{
    required: true,
    message: '试题类型' + errorStr,
    trigger: 'change'
  }],
  difficult: [{
    required: true,
    message: '试题难度' + errorStr,
    trigger: 'change'
  }],
  courseId: [{
    required: true,
    message: '所属课程' + errorStr,
    trigger: 'change'
  }],
  num: [{
    required: true,
    message: '抽取题量' + errorStr,
    trigger: 'blur'
  }, {
    pattern: sortReg,
    message: '抽取题量格式错误！',
    trigger: 'blur'
  }],
  score: [{
    required: true,
    message: '每题分值' + errorStr,
    trigger: 'blur'
  }, {
    pattern: sortReg,
    message: '每题分值格式错误！',
    trigger: 'blur'
  }]
}

/* 培训 */
export const CertificateFormRules = {
  title: [{
    required: true,
    message: '培训名称' + errorStr,
    trigger: 'blur,change'
  }],
  pic: [{
    required: true,
    message: '封面图' + errorStr,
    trigger: 'blur,change'
  }],
  price: ComRules.price,
  passedScore: [{
    required: true,
    message: '达标分值' + errorStr,
    trigger: 'blur'
  }, {
    pattern: sortReg,
    message: '达标分值格式错误',
    trigger: 'blur'
  }],
  chance: [{
    required: true,
    message: '可报考次数' + errorStr,
    trigger: 'blur'
  }, {
    pattern: sortReg,
    message: '可报考次数格式错误',
    trigger: 'blur'
  }],
  learningHours: [{
    required: true,
    message: '培训周期' + errorStr,
    trigger: 'blur'
  }, {
    pattern: sortReg,
    message: '培训周期格式错误',
    trigger: 'blur'
  }],
  useTime: [{
    required: true,
    message: '考试时长' + errorStr,
    trigger: 'blur'
  }, {
    pattern: sortReg,
    message: '考试时长格式错误',
    trigger: 'blur'
  }],
  freeTimes: [{
    required: true,
    message: '可免考次数' + errorStr,
    trigger: 'blur'
  }, {
    pattern: sortReg,
    message: '可免考次数格式错误',
    trigger: 'blur'
  }],
  courseIds: [{
    required: true,
    message: '必学课程' + errorStr,
    trigger: 'blur,change'
  }],
  paperIds: [{
    required: true,
    message: '试卷' + errorStr,
    trigger: 'blur,change'
  }],
  courseType: [{
    required: true,
    message: '达标方式' + errorStr,
    trigger: 'blur,change'
  }],
  courseScore: [{
    required: true,
    message: '达标积分' + errorStr,
    trigger: 'blur,change'
  }]
}

/* 热词名称 */
export const hotWordFormRules = {
  keywords: [{
    required: true,
    message: '热词名称' + errorStr,
    trigger: 'blur'
  }, {
    pattern: /^[\u4e00-\u9fffa-zA-Z0-9]{1,50}$/,
    message: '热词名称格式有误!(最多50字)',
    trigger: 'blur'
  }],
  productList: [{
    required: true,
    message: '热词商品' + errorStr,
    trigger: 'change'
  }],
  sort: [{
    required: true,
    message: '热词排序' + errorStr,
    trigger: 'blur'
  }, {
    pattern: sortReg,
    message: '排序格式有误!',
    trigger: 'blur'
  }]
}

/* 活动 */
export const activityFormRules = {
  title: [{
    required: true,
    message: '活动名称' + errorStr,
    trigger: 'blur'
  }],
  startTime: [{
    required: true,
    message: '开始时间' + errorStr,
    trigger: 'change'
  }],
  endTime: [{
    required: true,
    message: '结束时间' + errorStr,
    trigger: 'change'
  }],
  status: [{
    required: true,
    message: '活动状态' + errorStr,
    trigger: 'change'
  }],
  payWay: [{
    required: true,
    message: '支付方式' + errorStr,
    trigger: 'change'
  }],
  productData: [{
    required: true,
    message: '活动商品' + errorStr,
    trigger: 'change'
  }],
  sort: [{
    pattern: sortReg,
    message: '排序' + errorStr,
    trigger: 'change'
  }]
}

export const classActivityFormRules = {
  navigationName: [{
    required: true,
    message: '活动导航名称' + errorStr,
    trigger: 'blur'
  }],
  status: [{
    required: true,
    message: '活动导航状态' + errorStr,
    trigger: 'change'
  }],
  sort: [{
    required: true,
    message: '导航排序' + errorStr,
    trigger: 'blur'
  }, {
    pattern: sortReg,
    message: '排序格式有误!',
    trigger: 'blur'
  }],
  href: [{
    required: true,
    message: '导航跳转链接' + errorStr,
    trigger: 'blur'
  }],
  imgUrl: [{
    required: true,
    message: '导航图标' + errorStr,
    trigger: 'change'
  }]
}

// 现金和单价的倍数关系，后期可以存储到数据库中，进行人工设置
export const priceMultiple = 2.5;